
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="xms">
    <meta name="author" content="Xms">
    <link rel="icon" href="/content/favicon.ico">

    <title>菜单设置</title>

    <!-- Bootstrap core CSS -->
    <link href="/content/css/bootstrap3.3.5/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/content/css/font-awesome.min.css" rel="stylesheet">
    <link href="/content/css/common.css" rel="stylesheet">
    <link href="/content/js/jquery-toast/jquery.toast.min.css" rel="stylesheet">
    <link id="themeLink" href="/content/css/theme/default.css" rel="stylesheet" />
    <!-- Bootstrap core JavaScript ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="/content/js/jquery.min.js"></script>
    <script src="/content/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="/content/js/ie10-viewport-bug-workaround.js"></script>
    <script src="/content/js/jquery.bootstrap.min.js"></script>
    <script src="/content/js/json2.js"></script>
    <script src="/content/js/xms.utility.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.core.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.widget.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js"></script>
    <script src="/content/js/jquery-toast/jquery.toast.min.js"></script>
    <script src="/content/js/xms.jquery.js"></script>
    <script src="/content/js/xms.web.js"></script>
    <script src="/content/js/commonlabels.js"></script>
    <script src="/content/js/common/pagecontext.js"></script>
    <script src="/api/user/usercontext"></script>
    <script>
    jQuery(function () {
        Xms.Web.Loading();
        if (typeof parent !== 'undefined') {
            if (parent != window) {//判断当前页面是否为子页面
                $('body').addClass('xms-subpage');
            }
        }
    });
    function changeTheme(body,themename) {
        $("#themeLink").attr('href', '/content/css/theme/' + themename+'.css');
    }
</script>
    <link href="/content/css/jqtree.css" rel="stylesheet">
    <style>
        .xms-mutilauto-input {
            border: 1px solid #ccc;
        }
    </style>
    <style>
        body {
            padding-top: 0;
        }
    </style>
</head>

<body data-spy="scroll" data-target="#myScrollspy">
<div class="container-fluid" id="body">
    <div class="row">
        <div class="shadeBox" style="background-color:#000000; opacity:0.5;width:100%;position:absolute;z-index:10;display:none;"></div>
        <div class="col-md-12" id="main" style="margin-bottom:80px;">
            <div><br class="breadcrumb" /></div>
            <div id="content"></div>
            <div class="page-render-wrap">
                <!--main-->

                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-4">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <h3 class="panel-title">
                                        <a data-toggle="collapse"
                                           href="#collapseOne">
                                            <strong>菜单</strong>
                                        </a>
                                    </h3>
                                </div>
                                <div id="collapseOne" class="panel-collapse collapse in">
                                    <div class="xms-tree-toolbar panel-body">
                                        <div class="xms-tree-toolbtn btn btn-xs btn-default"><span class="glyphicon glyphicon-minus"></span> 全部展开</div>
                                        <div class="xms-tree-toolbtn btn btn-xs btn-default"><span class="glyphicon glyphicon-plus"></span> 全部缩起</div>
                                    </div>
                                    <div class="panel-body" style="max-height:450px;overflow-y:scroll;">
                                        <div id="tree1" data-url="/xms/api/security/privilege/tree"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-8">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    <h3 class="panel-title">
                                        <a data-toggle="collapse"
                                           href="#collapseTwo">
                                            <strong>编辑</strong>
                                        </a>
                                    </h3>
                                </div>
                                <div id="collapseTwo" class="panel-collapse collapse in">
                                    <div class="panel-body" style="max-height:450px;overflow-y:scroll;">
                                        <form action="/xms/api/security/privilege/create" data-jsonajax="true" data-formdata="false" method="post" id="editform" class="form-horizontal" role="form">
                                            <input id="PrivilegeId" name="privilegeid" data-name="privilegeid" type="hidden" value="" />
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label">操作</label>
                                                <div class="col-sm-10">
                                                    <label class="radio-inline">
                                                        <input class="required" name="actionstatus" type="radio" value="0"> 编辑本节点
                                                    </label>
                                                    <label class="radio-inline">
                                                        <input class="required" name="actionstatus" type="radio" value="1" checked> 新增子节点
                                                    </label>
                                                    <label class="radio-inline">
                                                        <input class="required" name="actionstatus" type="radio" value="2"> 新增同级节点
                                                    </label>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="ParentPrivilegeName">上级</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control disabled" disabled="disabled" id="ParentPrivilegeName" name="parentprivilegename" data-name="parentprivilegename" type="text" />
                                                    <input class="form-control" id="ParentPrivilegeId" name="parentprivilegeid" data-name="parentprivilegeid" type="hidden" />
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="DisplayName">显示名称</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control" data-val="true" data-val-length="长度20以内" data-val-length-max="20" data-val-required="必填项" id="DisplayName" maxlength="20" name="displayname" data-name="displayname" type="text" />
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12 hide">
                                                <label class="col-sm-2 control-label" for="SystemName">区域(area)</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control" data-val="true" data-val-length="长度50以内" data-val-length-max="50" id="SystemName" maxlength="50" name="systemname" data-name="systemname" type="text" />
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12 hide">
                                                <label class="col-sm-2 control-label" for="ClassName">控制器(controller)</label>
                                                <div class="col-sm-10">
                                                    <div class="input-group">
                                                        <input class="form-control input-sm" data-val="true" data-val-length="长度50以内" data-val-length-max="50" id="ClassName" maxlength="50" name="classname" data-name="classname" type="text" />
                                                        <span class="input-group-btn">
                                            <button class="btn btn-default btn-sm" type="button" onclick="Xms.Web.OpenDialog('/tool/selectactionsdialog?singlemode=true','bindSelectedAction')">
                                                <span class="glyphicon glyphicon-search"></span>
                                            </button>
                                        </span>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12 hide">
                                                <label class="col-sm-2 control-label" for="MethodName">动作(action)</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control" data-val="true" data-val-length="长度50以内" data-val-length-max="50" id="MethodName" maxlength="50" name="methodname" data-name="methodname" type="text" />
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12 hide">
                                                <label class="col-sm-2 control-label" for="BigIcon">大图标</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control" id="BigIcon" name="bigicon" data-name="bigicon" type="text" />
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="SmallIcon">小图标</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control" id="SmallIcon" name="smallicon" data-name="smallicon" type="text" />
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="Url">链接</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control" data-val="true" data-val-length="长度200以内" data-val-length-max="200" id="Url" maxlength="200" name="url" data-name="url" type="text" />
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="OpenTarget">目标窗口</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control" id="OpenTarget" name="opentarget" data-name="opentarget" type="text" />
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="AuthorizationEnabled1">权限验证</label>
                                                <div class="col-sm-10">
                                                    <label class="radio-inline">
                                                        <input data-val="true" data-val-required="必填项" id="AuthorizationEnabled1" name="authorizationenabled" data-name="authorizationenabled" type="radio" value="true" /> 启用
                                                    </label>
                                                    <label class="radio-inline">
                                                        <input id="AuthorizationEnabled0" name="authorizationenabled" data-name="authorizationenabled" type="radio" value="false" /> 禁用
                                                    </label>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="IsVisibled1">显示状态</label>
                                                <div class="col-sm-10">
                                                    <label class="radio-inline">
                                                        <input data-val="true" data-val-required="必填项" id="IsVisibled1" name="isvisibled" data-name="isvisibled" type="radio" value="true" /> 显示
                                                    </label>
                                                    <label class="radio-inline">
                                                        <input id="IsVisibled0" name="isvisibled" data-name="isvisibled" type="radio" value="false" /> 隐藏
                                                    </label>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="DisplayOrder">排序</label>
                                                <div class="col-sm-10">
                                                    <input class="form-control" id="DisplayOrder" name="DisplayOrder" type="text" />
                                                    <span class="help-block">
                                        新增时自动计算排序号，左边拖动排序后将重置排序号
                                    </span>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="Description">描述</label>
                                                <div class="col-sm-10">
                                    <textarea class="form-control" id="Description" name="description" data-name="description" rows="3">
</textarea>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12 text-center" id="form-buttons">
                                                <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-saved"></span> 保存</button>
                                                <button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> 重置</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <nav class="navbar navbar-default navbar-fixed-bottom hide" role="navigation" id="body-footer">
                <div class="container">
                    <div class="navbar-form navbar-right" id="body-footer-content">
                    </div>
                </div>
            </nav>
        </div>
    </div>
</div>

<script src="/content/js/xms.utility.js"></script>
<script src="/content/js/tree.jquery.js"></script>
<script src="/content/js/jquery.form.js"></script>
<script src="/content/js/jquery.cookie.js"></script>
<script src="/content/js/jquery-validate/jquery.validate.min.js"></script>
<script src="/content/js/jquery-validate/localization/messages_zh.min.js"></script>
<script>
    var bsicons = ['glyphicon glyphicon-asterisk',
        'glyphicon glyphicon-plus',
        'glyphicon glyphicon-minus',
        'glyphicon glyphicon-euro',
        'glyphicon glyphicon-cloud',
        'glyphicon glyphicon-envelope',
        'glyphicon glyphicon-pencil',
        'glyphicon glyphicon-glass',
        'glyphicon glyphicon-music',
        'glyphicon glyphicon-search',
        'glyphicon glyphicon-heart',
        'glyphicon glyphicon-star',
        'glyphicon glyphicon-star-empty',
        'glyphicon glyphicon-user',
        'glyphicon glyphicon-film',
        'glyphicon glyphicon-th-large',
        'glyphicon glyphicon-th',
        'glyphicon glyphicon-th-list',
        'glyphicon glyphicon-ok',
        'glyphicon glyphicon-remove',
        'glyphicon glyphicon-zoom-in',
        'glyphicon glyphicon-zoom-out',
        'glyphicon glyphicon-off',
        'glyphicon glyphicon-signal',
        'glyphicon glyphicon-cog',
        'glyphicon glyphicon-trash',
        'glyphicon glyphicon-home',
        'glyphicon glyphicon-file',
        'glyphicon glyphicon-time',
        'glyphicon glyphicon-road',
        'glyphicon glyphicon-download-alt',
        'glyphicon glyphicon-download',
        'glyphicon glyphicon-upload',
        'glyphicon glyphicon-inbox',
        'glyphicon glyphicon-play-circle',
        'glyphicon glyphicon-repeat',
        'glyphicon glyphicon-refresh',
        'glyphicon glyphicon-list-alt',
        'glyphicon glyphicon-lock',
        'glyphicon glyphicon-flag',
        'glyphicon glyphicon-headphones',
        'glyphicon glyphicon-volume-off',
        'glyphicon glyphicon-volume-down',
        'glyphicon glyphicon-volume-up',
        'glyphicon glyphicon-qrcode',
        'glyphicon glyphicon-barcode',
        'glyphicon glyphicon-tag',
        'glyphicon glyphicon-tags',
        'glyphicon glyphicon-book',
        'glyphicon glyphicon-bookmark',
        'glyphicon glyphicon-print',
        'glyphicon glyphicon-camera',
        'glyphicon glyphicon-font',
        'glyphicon glyphicon-bold',
        'glyphicon glyphicon-italic',
        'glyphicon glyphicon-text-height',
        'glyphicon glyphicon-text-width',
        'glyphicon glyphicon-align-left',
        'glyphicon glyphicon-align-center',
        'glyphicon glyphicon-align-right',
        'glyphicon glyphicon-align-justify',
        'glyphicon glyphicon-list',
        'glyphicon glyphicon-indent-left',
        'glyphicon glyphicon-indent-right',
        'glyphicon glyphicon-facetime-video',
        'glyphicon glyphicon-picture',
        'glyphicon glyphicon-map-marker',
        'glyphicon glyphicon-adjust',
        'glyphicon glyphicon-tint',
        'glyphicon glyphicon-edit',
        'glyphicon glyphicon-share',
        'glyphicon glyphicon-check',
        'glyphicon glyphicon-move',
        'glyphicon glyphicon-step-backward',
        'glyphicon glyphicon-fast-backward',
        'glyphicon glyphicon-backward',
        'glyphicon glyphicon-play',
        'glyphicon glyphicon-pause',
        'glyphicon glyphicon-stop',
        'glyphicon glyphicon-forward',
        'glyphicon glyphicon-fast-forward',
        'glyphicon glyphicon-step-forward',
        'glyphicon glyphicon-eject',
        'glyphicon glyphicon-chevron-left',
        'glyphicon glyphicon-chevron-right',
        'glyphicon glyphicon-plus-sign',
        'glyphicon glyphicon-minus-sign',
        'glyphicon glyphicon-remove-sign',
        'glyphicon glyphicon-ok-sign',
        'glyphicon glyphicon-question-sign',
        'glyphicon glyphicon-info-sign',
        'glyphicon glyphicon-screenshot',
        'glyphicon glyphicon-remove-circle',
        'glyphicon glyphicon-ok-circle',
        'glyphicon glyphicon-ban-circle',
        'glyphicon glyphicon-arrow-left',
        'glyphicon glyphicon-arrow-right',
        'glyphicon glyphicon-arrow-up',
        'glyphicon glyphicon-arrow-down',
        'glyphicon glyphicon-share-alt',
        'glyphicon glyphicon-resize-full',
        'glyphicon glyphicon-resize-small',
        'glyphicon glyphicon-exclamation-sign',
        'glyphicon glyphicon-gift',
        'glyphicon glyphicon-leaf',
        'glyphicon glyphicon-fire',
        'glyphicon glyphicon-eye-open',
        'glyphicon glyphicon-eye-close',
        'glyphicon glyphicon-warning-sign',
        'glyphicon glyphicon-plane',
        'glyphicon glyphicon-calendar',
        'glyphicon glyphicon-random',
        'glyphicon glyphicon-comment',
        'glyphicon glyphicon-magnet',
        'glyphicon glyphicon-chevron-up',
        'glyphicon glyphicon-chevron-down',
        'glyphicon glyphicon-retweet',
        'glyphicon glyphicon-shopping-cart',
        'glyphicon glyphicon-folder-close',
        'glyphicon glyphicon-folder-open',
        'glyphicon glyphicon-resize-vertical',
        'glyphicon glyphicon-resize-horizontal',
        'glyphicon glyphicon-hdd',
        'glyphicon glyphicon-bullhorn',
        'glyphicon glyphicon-bell',
        'glyphicon glyphicon-certificate',
        'glyphicon glyphicon-thumbs-up',
        'glyphicon glyphicon-thumbs-down',
        'glyphicon glyphicon-hand-right',
        'glyphicon glyphicon-hand-left',
        'glyphicon glyphicon-hand-up',
        'glyphicon glyphicon-hand-down',
        'glyphicon glyphicon-circle-arrow-right',
        'glyphicon glyphicon-circle-arrow-left',
        'glyphicon glyphicon-circle-arrow-up',
        'glyphicon glyphicon-circle-arrow-down',
        'glyphicon glyphicon-globe',
        'glyphicon glyphicon-wrench',
        'glyphicon glyphicon-tasks',
        'glyphicon glyphicon-filter',
        'glyphicon glyphicon-briefcase',
        'glyphicon glyphicon-fullscreen',
        'glyphicon glyphicon-dashboard',
        'glyphicon glyphicon-paperclip',
        'glyphicon glyphicon-heart-empty',
        'glyphicon glyphicon-link',
        'glyphicon glyphicon-phone',
        'glyphicon glyphicon-pushpin',
        'glyphicon glyphicon-usd',
        'glyphicon glyphicon-gbp',
        'glyphicon glyphicon-sort',
        'glyphicon glyphicon-sort-by-alphabet',
        'glyphicon glyphicon-sort-by-alphabet-alt',
        'glyphicon glyphicon-sort-by-order',
        'glyphicon glyphicon-sort-by-order-alt',
        'glyphicon glyphicon-sort-by-attributes',
        'glyphicon glyphicon-sort-by-attributes-alt',
        'glyphicon glyphicon-unchecked',
        'glyphicon glyphicon-expand',
        'glyphicon glyphicon-collapse-down',
        'glyphicon glyphicon-collapse-up',
        'glyphicon glyphicon-log-in',
        'glyphicon glyphicon-flash',
        'glyphicon glyphicon-log-out',
        'glyphicon glyphicon-new-window',
        'glyphicon glyphicon-record',
        'glyphicon glyphicon-save',
        'glyphicon glyphicon-open',
        'glyphicon glyphicon-saved',
        'glyphicon glyphicon-import',
        'glyphicon glyphicon-export',
        'glyphicon glyphicon-send',
        'glyphicon glyphicon-floppy-disk',
        'glyphicon glyphicon-floppy-saved',
        'glyphicon glyphicon-floppy-remove',
        'glyphicon glyphicon-floppy-save',
        'glyphicon glyphicon-floppy-open',
        'glyphicon glyphicon-credit-card',
        'glyphicon glyphicon-transfer',
        'glyphicon glyphicon-cutlery',
        'glyphicon glyphicon-header',
        'glyphicon glyphicon-compressed',
        'glyphicon glyphicon-earphone',
        'glyphicon glyphicon-phone-alt',
        'glyphicon glyphicon-tower',
        'glyphicon glyphicon-stats',
        'glyphicon glyphicon-sd-video',
        'glyphicon glyphicon-hd-video',
        'glyphicon glyphicon-subtitles',
        'glyphicon glyphicon-sound-stereo',
        'glyphicon glyphicon-sound-dolby',
        'glyphicon glyphicon-sound-5-1',
        'glyphicon glyphicon-sound-6-1',
        'glyphicon glyphicon-sound-7-1',
        'glyphicon glyphicon-copyright-mark',
        'glyphicon glyphicon-registration-mark',
        'glyphicon glyphicon-cloud-download',
        'glyphicon glyphicon-cloud-upload',
        'glyphicon glyphicon-tree-conifer',
        'glyphicon glyphicon-tree-deciduous'];

    var btnColorArr = ['btn-default', 'btn-primary', 'btn-success', 'btn-info', 'btn-warning', 'btn-danger', 'btn-link'];
    var btnSizeArr = ['btn-lg', '', 'btn-sm', 'btn-xs'];
    var $tree = $('#tree1'), $form = $('#editform');
    var $editaction = $form.find("input[name='actionstatus'][value='0']");
    var $childaction = $form.find("input[name='actionstatus'][value='1']");
    var $siblingaction = $form.find("input[name='actionstatus'][value='2']");
    $(function () {
        initTree();
        //表单验证
        Xms.Web.Form($form, function (response) {
            Xms.Web.Toast(response.Content || response.ErrorMessage, response.IsSuccess);
            if (response.IsSuccess) {
                loadTree();
                $form.resetForm();
                $childaction.trigger("click");
            }
        }, null, function(){
            var status = $form.find("input[name='actionstatus']:checked").val();
            if (status == 0)//编辑本节点
            {
                $form.prop('action', '/xms/api/security/privilege/update');
            }
            else //新增节点
            {
                $form.prop('action', '/xms/api/security/privilege/create');
            }
        });

        //操作类型
        $form.find("input[name='actionstatus']").click(function () {
            var id = $form.find("input[name='privilegeid']").val();
            var node = $tree.tree('getSelectedNode');
            if (id == '' || id == Xms.Utility.Guid.EmptyGuid.ToString()) {
                if (node != false) {
                    id = node.id;
                }
            }
            $form.find("input[name='actionstatus']").prop("checked", false);
            if ($(this).val() == 0)//编辑本节点
            {
                $form.prop('action', '/xms/api/security/privilege/update');
                doEditAction(id);
            }
            else if ($(this).val() == 1)//新增子节点
            {
                $form.prop('action', '/xms/api/security/privilege/create');
                doChildAction(id);
            }
            else if ($(this).val() == 2)//新增同级节点
            {
                $form.prop('action', '/xms/api/security/privilege/create');
                doCreateAction(id, node);
            }
        });

        $('#BigIcon').xmsAutoComplete({
            datas: bsicons,
            itemClass: 'iconsarr',
            itemTmpl: '<li class="{{itemClass}} {{itemOther}}" value="{{itemValue}}">{{itemTitle}}</li>',
            dataFilter: function (data) {
                var res = [];
                $.each(data, function (i, n) {
                    var obj = {
                        value: n,
                        other: n,
                    }
                    res.push(obj);
                });
                return res;
            }
            , overflowPar: $('#BigIcon').parents('.panel-body:first')
            ,offsetL:13
        });

        $('#SmallIcon').xmsAutoComplete({
            datas: bsicons,
            itemClass: 'iconsarr',
            itemTmpl: '<li class="{{itemClass}} {{itemOther}}" value="{{itemValue}}">{{itemTitle}}</li>',
            dataFilter: function (data) {
                var res = [];
                $.each(data, function (i, n) {
                    var obj = {
                        value: n,
                        other: n,
                    }
                    res.push(obj);
                });
                return res;
            }
            , overflowPar: $('#BigIcon').parents('.panel-body:first')
            , offsetL: 13
        });

        var entitySelect = $('#Url');
        // entitySelect.empty();
        entitySelect.mutilAutoComplete({
            getType: 'ajax',
            ajax: {
                url: "/api/schema/entity/list",
                data: { getall: true },
            },
            replaceList: [{ key: 'itemClass', value: 'itemClass' }, { key: 'itemValue', value: 'entityid' }, { key: 'entityname', value: 'name' }, { key: 'itemOther', value: 'other' }, { key: 'itemTitle', value: 'localizedname' }],
            dataFilter: function (data) {
                return data.content;
            }
            ,loadDefaultValue:true
            ,itemTmpl: '<li class="{{itemClass}}" value="{{itemValue}}" data-name="{{entityname}}">{{itemOther}}{{itemTitle}}</li>'
            , defaultSubmit: false
            , submithandler: function (obj,$target) {
                obj.box.val( '/entity/list?entityname=' + $(this).attr('data-name'));
                obj.ul.hide();
                obj.vInput.val( '/entity/list?entityname=' + $(this).attr('data-name'));
                obj.value = $(this).attr('value');
                obj.wrap.attr('data-isactive', false);
                obj.box.trigger('xmsAutoItem.click');
            }

        });

        loadTreeToolbar();
    });
    function loadTreeToolbar() {
        var $collapseOne = $('#collapseOne');
        $collapseOne.children('.xms-tree-toolbar').children('.xms-tree-toolbtn:first').on('click', function () {
            //$tree.find('.jqtree-folder').removeClass('jqtree-closed')
            $tree.tree('openAllNodes');
        });
        $collapseOne.children('.xms-tree-toolbar').children('.xms-tree-toolbtn:last').on('click', function () {
            // $tree.find('.jqtree-folder').addClass('jqtree-closed')
            $tree.tree('closeAllNodes');
        });
    }
    function doEditAction(id) {
        if (id == Xms.Utility.Guid.EmptyGuid.ToString()) {
            $.messager.popup(LOC_NOTSPECIFIED_RECORD);
            return;
        }
        getPrivilegeInfo(id);
        $editaction.prop("checked", true);
    }
    function doChildAction(id) {
        $form.resetForm();
        $form.find("input[name='parentprivilegeid']").val(id);
        $form.find("input[name='privilegeid']").val(Xms.Utility.Guid.EmptyGuid.ToString());
        $childaction.prop("checked", true);
    }
    function doCreateAction(id, node) {
        if (id == Xms.Utility.Guid.EmptyGuid.ToString()) {
            $.messager.popup(LOC_NOTSPECIFIED_RECORD);
            return;
        }
        $form.resetForm();
        $form.find("input[name='parentprivilegeid']").val(node.parent ? node.parent.id : Xms.Utility.Guid.EmptyGuid.ToString());
        $form.find("input[name='privilegeid']").val(Xms.Utility.Guid.EmptyGuid.ToString());
        $form.find("input[name='authorizationenabled'][value='true']").prop('checked', true);
        $form.find("input[name='isvisibled'][value='true']").prop('checked', true);
        $siblingaction.prop("checked", true);
    }
    function initTree() {
        $tree.tree({
            dragAndDrop: true
            , autoOpen: true
            , saveState: 'admin-menutree'
            , onCreateLi: function (node, $li) {
                if (node.id != Xms.Utility.Guid.EmptyGuid.ToString()) {
                    $li.find('.jqtree-title').after('&nbsp;&nbsp;<a class="glyphicon glyphicon-trash" title="'+LOC_DELETE+'" href="javascript:removeNode(\'' + node.id + '\')" nodeid="' + node.id + '"></a>');
                }
            },
            dataFilter: function (data) {
                //var res = Xms.Web.GetAjaxResult(data).content;
                console.log('tree', data);
                return data;
            }
            , onCanMoveTo: function (moved_node, target_node, position) {
                //console.log(moved_node, target_node, position);
                var moveid = moved_node.id;
                var targetid = target_node.id;
                var previd = moved_node.getPreviousNode() != null ? moved_node.getPreviousNode().id : 0;
                var nextid = moved_node.getNextNode() != null ? moved_node.getNextNode().id : 0;
                console.log(position + " moveparentid=" + moved_node.parent.id + ",targetid=" + target_node.id + ",targetparentid=" + target_node.parent.id);

                var flag = false;
                if (position == "inside" && moved_node.parent.id == target_node.id) {
                    flag = true;
                }
                else if (position == "after" && moved_node.parent.id == target_node.parent.id) {
                    flag = true;
                }
                return flag;
            }
            , selectable: true
        });

        $tree.bind(
            'tree.move',
            function (event) {
                console.log('moved_node', event.move_info.moved_node);
                console.log('target_node', event.move_info.target_node);
                console.log('position', event.move_info.position);
                console.log('previous_parent', event.move_info.previous_parent);
                var moveid = event.move_info.moved_node.id;
                var targetid = event.move_info.target_node.id;
                var parentid = event.move_info.previous_parent.id;
                var position = event.move_info.position;
                $.get(ORG_SERVERURL + "/api/security/privilege/move?moveid=" + moveid + "&targetid=" + targetid + "&parentid=" + parentid + "&position=" + position, function (response) {
                    console.log(response);
                    $tree.tree('reload');
                });
            }
        );
        $tree.bind(
            'tree.select',
            function (event) {
                if (event.node) {
                    // node was selected
                    var node = event.node;
                    $tree.tree('openNode', node);
                    $form.find("input[name='actionstatus']").prop("checked", false);
                    if (node.id == Xms.Utility.Guid.EmptyGuid.ToString()) {
                        doChildAction(Xms.Utility.Guid.EmptyGuid.ToString());
                        return;
                    }
                    doEditAction(node.id);
                }
            }
        );
    }
    function getPrivilegeInfo(id) {
        Xms.Web.GetJson("/api/security/privilege/getbyid/" + id, null, function (data) {
            console.log(data);
            if (!data) return;
            var entity = data.content;
            console.log(entity);
            $form.resetForm();
            $editaction.prop("checked", true);
            //$form.find("input[name='parentprivilegeid']").val(entity.parentprivilegeid);
            for (var p in entity) {
                if (typeof (entity[p]) != "function") {
                    var value = entity[p] == null ? "" : entity[p];
                    var target = $form.find("input[name='" + p.toLowerCase() + "']");
                    if (target.is(":radio") || target.is(":checkbox")) {
                        target.each(function (i, n) {
                            if ($(n).val().toLowerCase() == value.toString().toLowerCase()) {
                                $(n).prop("checked", true);
                            }
                        });
                    }
                    else {
                        target.val(entity[p]);
                        if (p == "url") {
                            target.siblings('.xms-mutilauto-wrap').children('input').val(entity[p])
                        }
                    }
                }
            }
        });
    }
    function removeNode(id) {
        var node = $tree.tree('getNodeById', id);
        Xms.Web.Del(id, "/api/security/privilege/deletebyid", false, function (response) {
            if (response.IsSuccess) {
                $tree.tree('removeNode', node);
                $form.resetForm();
            }
        });
    }
    function loadTree() {
        $tree.tree('reload');
    }
    function bindSelectedAction(result) {
        $('#SystemName').val('admin');
        $('#ClassName').val(result[0].classname.replace('Controller', ''));
        $('#MethodName').val(result[0].methodname);
        $('#DisplayName').val(result[0].displayname);
        $('#Url').val(result[0].classname.replace('Controller', '') + '/' + result[0].methodname);
    }
</script>

</body>
</html>